package net.edwardstx.brian.rpn;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import net.edwardstx.brian.rpn.exception.InvalidArguments;
import net.edwardstx.brian.rpn.exception.UnknownOperation;
import net.edwardstx.brian.rpn.types.RPNInteger;
import net.edwardstx.brian.rpn.types.RPNRational;
import net.edwardstx.brian.rpn.types.RPNString;

public class TextRPN {

	public static void main(String[] args) throws IOException {
		RPNEngineImpl rpn = new RPNEngineImpl();
		rpn.register(RPNInteger.TYPE);
		rpn.register(RPNRational.TYPE);
		rpn.register(RPNString.TYPE);
		String input = null;
		while(input == null || "exit".compareToIgnoreCase(input.trim()) != 0){
			BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
			System.out.print(":");
			input = in.readLine();
			try {
				rpn.input(input);
			} catch (UnknownOperation | InvalidArguments e) {
				e.printStackTrace();
			}
			for(int i = rpn.depth(); i > 0; i--){
				System.out.println(i + ">" + '\t' + rpn.get(i-1).toString());
			}
		}
	}

}
